import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
export const constantRouterMap = [

    {
        path: '/login',
        component: () => import('@/page/login'),
        name: 'login',
    },
    {
        path: '/',
        name: 'default',
        redirect: '/index'
    },
]

/**
 * 防止报 Error: Redirected when going from "/login" to "/index" via a navigation guard 这个错
 * 就是先进行了路由跳转后存数据
 */
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export default new Router({
    routes: constantRouterMap

})
